package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.GreenCertificateManagement;
import com.isdepci.project.carbon.domain.StationInfo;
import com.isdepci.project.carbon.service.IGreenCertificateManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 绿证管理Controller
 *
 * @author isdepci
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/greenCertificate/certificate")
public class GreenCertificateManagementController extends BaseController {
    @Autowired
    private IGreenCertificateManagementService greenCertificateManagementService;



    @GetMapping("/dict")
    public AjaxResult selectStationInfoDict(){
        List<StationInfo> list = greenCertificateManagementService.selectStationInfoDict();
        return AjaxResult.success(list);
    }




    /**
     * 查询绿证管理列表
     */
    @PreAuthorize("@ss.hasPermi('greenCertificate:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(GreenCertificateManagement greenCertificateManagement){
        startPage();
        List<GreenCertificateManagement> list = greenCertificateManagementService.selectGreenCertificateManagementList(greenCertificateManagement);
        return getDataTable(list);
    }

    /**
     * 导出绿证管理列表
     */
    @PreAuthorize("@ss.hasPermi('greenCertificate:certificate:export')")
    @Log(title = "绿证管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GreenCertificateManagement greenCertificateManagement){
        List<GreenCertificateManagement> list = greenCertificateManagementService.selectGreenCertificateManagementList(greenCertificateManagement);
        ExcelUtil<GreenCertificateManagement> util = new ExcelUtil<GreenCertificateManagement>(GreenCertificateManagement.class);
        return util.exportExcel(list, "certificate");
    }

    /**
     * 获取绿证管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('greenCertificate:certificate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(greenCertificateManagementService.selectGreenCertificateManagementById(id));
    }

    /**
     * 新增绿证管理
     */
    @PreAuthorize("@ss.hasPermi('greenCertificate:certificate:add')")
    @Log(title = "绿证管理", businessType = BusinessType.INSERT)
    @PostMapping("/addGreenCertificate")
    public AjaxResult add(@RequestBody GreenCertificateManagement greenCertificateManagement){
        return toAjax(greenCertificateManagementService.insertGreenCertificateManagement(greenCertificateManagement));
    }

    /**
     * 修改绿证管理
     */
    @PreAuthorize("@ss.hasPermi('greenCertificate:certificate:edit')")
    @Log(title = "绿证管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updateGreenCertificate")
    public AjaxResult edit(@RequestBody GreenCertificateManagement greenCertificateManagement){
        return toAjax(greenCertificateManagementService.updateGreenCertificateManagement(greenCertificateManagement));
    }

    /**
     * 删除绿证管理
     */
    @PreAuthorize("@ss.hasPermi('greenCertificate:certificate:remove')")
    @Log(title = "绿证管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(greenCertificateManagementService.deleteGreenCertificateManagementByIds(ids));
    }
}
